package com.zyx.wanshu.util;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author zyx
 * @since 2022/7/17 07:38
 * desc: web工具类
 */
@Component
public class WebUtils {

    public String passwordEncoder(String password) {
        return new BCryptPasswordEncoder().encode(password);
    }

    public String loginUserName(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        return userDetails.getUsername();
    }
}
